package org.dprojects.iwebshare.db.user;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.dprojects.iwebshare.db.path.Directory;

@Entity
public class User implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8978855916343197978L;
	
	private long id;
	
	private String username;
	private String password;
	
	private List<Directory> dirs; 
	
	public void setId(long id) {
		this.id = id;
	}
	
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getUsername() {
		return username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword() {
		return password;
	}
	
	public void setDirs(List<Directory> dirs) {
		this.dirs = dirs;
	}
	
	@ManyToMany(targetEntity=Directory.class,cascade={CascadeType.PERSIST, CascadeType.MERGE},fetch=FetchType.LAZY)
	@JoinTable(
        name="USER_DIR",
        joinColumns={@JoinColumn(name="USER_ID")},
        inverseJoinColumns={@JoinColumn(name="DIR_ID")}
    )
	public List<Directory> getDirs() {
		return dirs;
	}

}
